package updater;

import interactions.Interaction;
import java.util.ArrayList;

import sprite.Sprite;


/**
 * Updates interactions.
 * 
 * @author Seon Kang
 * @author Yaqi Zhang
 * @author Guy Tracy
 */

public class InteractionUpdater implements Updater {
    private ArrayList<Sprite> mySpriteList = new ArrayList<Sprite>();
    private ArrayList<Interaction> myInteractionList = new ArrayList<Interaction>();
    /**
     * 
     * @param spritelist 
     * @param interactionlist 
     */
    public InteractionUpdater(ArrayList<Sprite> spritelist) {
        setSpriteList(spritelist);
    }

    /**
     * Takes every pair of Sprites and then checks to see if they are interacting via any of the
     * defined interactions. It's slow, but as long as these lists aren't too big, it should be
     * okay. If anyone has a better way of implementing, feel free to do so.
     */
    @Override

    public void update() {
        for (Sprite sprite1: mySpriteList) {
            for (Sprite sprite2: mySpriteList) {
                for (Interaction interaction: myInteractionList) {
                    if (interaction.isInteracting(sprite1, sprite2)) {
                        interaction.doStrategyAction(sprite1, sprite2);
                    }
                }
            }
        }
    }

    /**
     * 
     * @return
     */
    public ArrayList<Sprite> getSpriteList() {
        return mySpriteList;
    }

    /**
     * 
     * @param spritelist 
     */
    public void setSpriteList(ArrayList<Sprite> spritelist) {
        this.mySpriteList = spritelist;
    }

    protected ArrayList<Interaction> getInteractionList() {
        return myInteractionList;
    }

    protected void setInteractionList(ArrayList<Interaction> interactionlist) {
        this.myInteractionList = interactionlist;
    }
    
    public void addInteraction(Interaction interact){
        myInteractionList.add(interact);
    }
}
